import { Controller, Post, Body, UseGuards, Req, Get, Query } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto, ChangePasswordDto, UpdateUserDto } from './dto/user.dto';
import { ApiOperation, ApiTags, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { Request } from 'express';
import { PageRequest } from 'src/common/page-request/pageRequest';

@ApiBearerAuth()
@ApiTags('用户模块')
@Controller('user')
@UseGuards(JwtGuard)
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('/create')
  @ApiOperation({ summary: '添加新用户' })
  addUser(@Body() user: CreateUserDto) {
    return this.userService.create(user);
  }

  @Post('changePassword')
  @ApiOperation({ summary: '修改密码' })
  changePassword(@Req() req: Request, @Body() body: ChangePasswordDto) {
    return this.userService.changePassword(req, body);
  }

  @Post('getUsers')
  @ApiOperation({ summary: '查询所有有用户' })
  getUsers(@Body() body: PageRequest) {
    return this.userService.getUsers(body);
  }

  @Post('updateUser')
  @ApiOperation({ summary: '根据用户id更新用户信息' })
  updateUserById(@Body() body: UpdateUserDto) {
    return this.userService.updateUserById(body);
  }

  @Get('deleteUserById')
  @ApiOperation({ summary: '根据用户id删除用户' })
  @ApiQuery({ name: 'id' })
  deleteUSerById(@Query('id') id: number) {
    return this.userService.deleteUserById(id);
  }
}
